package Boundary;

import Entity.OperatoerDTO;

import Controller.IOperatoerDAO.DALException;
import Controller.OperatoerDAO;
import Controller.PasswordValidator;

import java.util.Scanner;

public class Graenseflade {
	
	OperatoerDTO opr = new OperatoerDTO();
	OperatoerDAO dao = new OperatoerDAO();
	PasswordValidator pv = new PasswordValidator();
	boolean go = true;
	
	public Graenseflade()		//added user options
	{
		while(go){
		System.out.println("1. Login");
		System.out.println("2. Change Password");
		System.out.println("3. Exit");
		
		System.out.println("Enter your choice");
		
		Scanner sc = new Scanner(System.in);		//user input
		String choice = sc.next();
		
		switch(choice)			//checking admin login
		{
		
		case "1":
			Scanner user = new Scanner(System.in);
			System.out.println("Enter ID:");
			String uname = user.next();
			System.out.println("Enter password:");
			String pwd = user.next();
			
			
				if((uname.equals("BOB")) && (pwd.equals("DGMNZ123")))
				{
				System.out.println("Login Successful");
				
				System.out.println();
				
				System.out.println("Select you choice");
				System.out.println("1. Create Operator");
				System.out.println("2. Udpate Operator");
				System.out.println("3. Delete Operator");
				}
			
				//Scanner s = new Scanner(System.in);		//user input
				String ch = sc.next();
				
				switch(ch)		//Admin entering operator data
				{
				case "1":
					Scanner admin = new Scanner(System.in);
					System.out.println("Enter ID");
					int ID = admin.nextInt();
					opr.setoprId(ID);
					
					System.out.println("Enter Name");
					String name = admin.next();
					opr.setoprNavn(name);
					
					System.out.println("Enter CPR");
					String cpr = admin.next();
					opr.setcpr(cpr);
					
					System.out.println("Enter Password");
					/*
  			   must contains one digit from 0-9
  			   must contains one lowercase characters
  			   must contains one uppercase characters
  			   must contains one special symbols in the list "@#$%"
       		  match anything with previous condition checking
             length at least 6 characters and maximum of 20	
					 */
					String pass = admin.next();
					while((pv.validate(pass)) == false)
					{
						System.out.println("Enter a new Password");
						pass = admin.next();
					}
					opr.setpassword(pass);
					
				
					try {				//try catch for createOperatoer
						dao.createOperatoer(opr);
					} catch (DALException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}	
				break;
			
			
		case "3":
			System.exit(0);;
			}
		System.out.println("Id: " + opr.getoprId() + "\nName: " + opr.getoprNavn()
				+ "\nCPR: " + opr.getcpr() + "\nPassword: " + opr.getpassword());
		System.out.println();
		}
	}
		
	//Login interface
		
/*	if(Id == 10 && passwd == "02304it")
	{
		int Id = sysadminInt();
	}
*/	
	//Operatorinterface
	
	//Sysadmininterface
/*	private int sysadminInt()
	{
		return 0;
	}
*/	
	//vægtdetaljerinterface
	}
